/**
 * Copyright (c) 2014 zhenrongbao.com, Inc. All Rights Reserved
 * @author: jiangshuguang
 * @Date  : 14-12-9
 * @Time  : 下午3:18
 * @brief :
 */
(function () {
    var $page = $('.activity-double12'),
        $lotteryInit = $page.find('.lottery-init'),
        $lotteryShare = $page.find('.lottery-share'),
        $lotteryDone = $page.find('.lottery-done'),
        $step = $page.find('.step'),
        $mask = $page.find('.mask'),
        img = __uri('./image/share.png');


    $step.find('.btn-get').click(function(){
        if($(this).hasClass('doing')){
            $mask.show();
            var param = {
                'else_activity_key':'-1'
            };
            if(P.data('else_activity_key')){
                param['else_activity_key'] = P.data('else_activity_key');
            }
            $.get('/activity/getdouble12lottery',param,function(ret,status){
                if(ret.error_no == 0){
                    if(P.data('else_activity_key')){
                        $mask.show().find('.content').text("你已经为你好友加了一元红包");
                        $mask.click(function(){
                            location.reload();
                        });
                        setTimeout(function(){
                            location.reload();
                        },2000);
                    }else{
                        location.reload();
                    }
                }else{
                    location.reload();
                }
            },"json");
        }
    });


    $step.find('.btn-share').click(function(){
        if($(this).hasClass('doing')){
            P.shareTip.showShare('' +
                '<div>分享成功后，更多的好友会帮你加红包哦~</div>' +
                '');
        }
    });


    $step.find('.btn-preview').click(function(){
        if($(this).hasClass('doing')){
            if(P.data('is_share') == "share"){
                location.href="/activity/double12list";
            }
        }
    });


    $lotteryInit.click(function(){
        $step.find('.btn-get').trigger('click');
    });

    $lotteryShare.click(function(){
        $step.find('.btn-share').trigger('click');
    });

    $lotteryDone.click(function(){
        $step.find('.btn-preview').trigger('click');
    });


    P.share.data({
        'imgUrl':location.protocol+'//'+location.host+'/'+img,
        'isAutoGetData':false,
        'lineLink':location.protocol+'//'+location.host+'/activity/double12?contact_from='+ P.data('contact_from')+'&else_activity_key='+(P.data('activity_key')),
        'appMessageTitle':'有诚意的红包，从来都没有乱七八糟的限制',
        'appMessageDescContent':'12元再加12元，免费领，无限用！',
        'timeLineTitle':'双十二送双十二，免费领，无限用！真正有诚意的红包...',
        onSend:function(res){
            $.get('/activity/doshare',function(ret,status){
                location.reload();
            },'json');
        }
    });

    //不使用默认的配置
    P.share.on('beforeGetData',function(){
        P.share.data({
            'isAutoGetData':false
        });
    });



})();